<template>
	<!-- 隐私政策窗口 -->
	<u-popup :mask-close-able="false" mode="bottom" v-model="popupShow">
		<view class="padding">
			<text>在你使用【超品配送】服务之前，请仔细阅读</text><text @tap="read"
				style="color: blue;">{{urlTitle}}</text><text>。如你同意{{urlTitle}}，请点击“同意”开始使用【超品配送】</text>
		</view>
		<view class="margin privacy-btn">
			<view class="item">
				<button @tap="back" class="btn cancel">拒绝</button>
			</view>
			<view class="item">
				<button open-type="agreePrivacyAuthorization" @agreeprivacyauthorization="handleAgree"
					class="btn">同意</button>
			</view>
		</view>
	</u-popup>
</template>

<script>
	export default {
		props: {
			isBack: {
				type: Boolean,
				default: false,
			},
		},
		data() {
			return {
				urlTitle: '',
				popupShow: false,
			}
		},
		methods: {
			handleAgree() {
				this.popupShow = false
			},
			back() {
				if (this.isBack === true) {
					uni.navigateBack()
				} else {
					this.handleAgree()
				}
			},
			read() {
				wx.openPrivacyContract()
			}
		},
		onReady() {
			const that = this

			wx.getPrivacySetting({
				success: (res) => {
					console.log("是否需要授权：", res.needAuthorization, "隐私协议的名称为：", res.privacyContractName)
					that.urlTitle = res.privacyContractName
					if (res.needAuthorization) {

						// 其他操作，如显示隐私政策弹窗
						that.popupShow = res.needAuthorization
					} else {
						that.popupShow = res.needAuthorization
					}
				},
				fail: () => {},
				complete: () => {},
			})
		}
	}
</script>

<style lang="scss" scoped>
	.btn {
		height: 80rpx;
		line-height: 80rpx;
		font-size: 28rpx;
		border-radius: 80rpx;
		background: linear-gradient(to right, #19be6b, #19be6b) !important;
		color: white;

		&::after {
			border: none;
		}
	}

	.padding {
		padding: 20rpx;
		box-sizing: border-box;
	}

	.margin {
		margin: 20rpx;
	}

	.privacy-btn {
		display: flex;
		gap: 20rpx;

		.item {
			flex: 1;
		}

		.cancel {
			background: #f8f8f8 !important;
			color: #333;
		}
	}
</style>